/*
 * MscsView.java
 */

package mscs.server.view;

import mscs.data.pojo.Person;
import mscs.server.admin.view.AddPersonPanel;
import mscs.server.admin.view.DelPersonPanel;
import mscs.server.admin.view.EditPersonPanel;
import mscs.server.admin.view.GeneralPanel;
import mscs.server.admin.view.SearchPersonPanel;
import mscs.server.globalManager.view.AddGoodsInfoPanel;
import mscs.server.globalManager.view.DeleteGoodsInfoPanel;
import mscs.server.globalManager.view.EditGoodsInfoPanel;
import mscs.server.globalManager.view.SearchGoodsInfoPanel;
import mscs.server.logic.NetUtil;
import mscs.server.promotion.view.GlobalProPanel;
import mscs.server.promotion.view.SpecProPanel;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.SingleFrameApplication;

/**
 * The application's main frame.
 */
public class MscsServerView extends FrameView {

    public MscsServerView(SingleFrameApplication app, Person person) {
        super(app);
        this.person = person;
        initComponents();
        this.getFrame().setSize(800, 600);
        setEnvironment();
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        jSplitPane1 = new javax.swing.JSplitPane();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTree1 = new javax.swing.JTree();

        mainPanel.setName("mainPanel"); // NOI18N

        jSplitPane1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jSplitPane1.setDividerLocation(120);
        jSplitPane1.setEnabled(false);
        jSplitPane1.setName("jSplitPane1"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        javax.swing.tree.DefaultMutableTreeNode treeNode1 = new javax.swing.tree.DefaultMutableTreeNode("root");
        javax.swing.tree.DefaultMutableTreeNode treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("用户管理");
        javax.swing.tree.DefaultMutableTreeNode treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("雇佣员工");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("查询员工");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("职位变化");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("员工离职");
        treeNode2.add(treeNode3);
        treeNode1.add(treeNode2);
        treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("商品管理");
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("添加商品");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("查询商品");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("编辑商品");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("删除商品");
        treeNode2.add(treeNode3);
        treeNode1.add(treeNode2);
        treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("销售策略");
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("全局策略");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("特定商品");
        treeNode2.add(treeNode3);
        treeNode1.add(treeNode2);
        treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("库存分析");
        treeNode1.add(treeNode2);
        jTree1.setModel(new javax.swing.tree.DefaultTreeModel(treeNode1));
        jTree1.setName("jTree1"); // NOI18N
        jTree1.setRootVisible(false);
        jTree1.setToggleClickCount(1);
        jTree1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTree1MouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jTree1);

        jSplitPane1.setLeftComponent(jScrollPane1);

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 701, Short.MAX_VALUE)
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
        );

        setComponent(mainPanel);
    }// </editor-fold>//GEN-END:initComponents

    private void jTree1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTree1MouseClicked
        if(jTree1.getSelectionPath() != null) {
        String option = jTree1.getSelectionPath().getLastPathComponent().toString();
        jSplitPane1.setDividerLocation(120);
        if("用户管理".equals(option)){
            this.jSplitPane1.setRightComponent(new GeneralPanel());
        }else if("雇佣员工".equals(option)){
            addPersonPanel.refreshTable();
            this.jSplitPane1.setRightComponent(this.addPersonPanel);
        }else if("查询员工".equals(option)){
            this.searchPersonPanel.refreshTable();
            this.jSplitPane1.setRightComponent(this.searchPersonPanel);
        }else if("职位变化".equals(option)){
            this.editPersonPanel.refreshTable();
            this.jSplitPane1.setRightComponent(this.editPersonPanel);
        }else if("员工离职".equals(option)){
            this.delPersonPanel.refreshTable();
            this.jSplitPane1.setRightComponent(this.delPersonPanel);
        } else if("商品管理".equals(option)){
            this.jSplitPane1.setRightComponent(new GeneralPanel());
        }else if("添加商品".equals(option)){
            this.addGoodsInfoPanel.refreshTable();
            this.jSplitPane1.setRightComponent(this.addGoodsInfoPanel);
        }else if("查询商品".equals(option)){
            this.searchGoodsInfoPanel.refreshTable();
            this.jSplitPane1.setRightComponent(this.searchGoodsInfoPanel);
        }else if("编辑商品".equals(option)){
            this.editGoodsInfoPanel.refreshTable();
            this.jSplitPane1.setRightComponent(this.editGoodsInfoPanel);
        }else if("删除商品".equals(option)){
            this.delGoodsInfoPanel.refreshTable();
            this.jSplitPane1.setRightComponent(this.delGoodsInfoPanel);
        }else if("销售策略".equals(option)){
            this.jSplitPane1.setRightComponent(new GeneralPanel());
        }else if("全局策略".equals(option)){
            GlobalProPanel globalProPanel = new GlobalProPanel(this);
            globalProPanel.refresh();
            this.jSplitPane1.setRightComponent(globalProPanel);
        }else if("特定商品".equals(option)){
            SpecProPanel specProPanel = new SpecProPanel(this);
            specProPanel.refresh();
            this.jSplitPane1.setRightComponent(specProPanel);
        } else if("库存分析".equals(option)) {
            ManageGoodsPanel manageGoodsPanel = new ManageGoodsPanel(this);
            manageGoodsPanel.refreshTable();
            this.jSplitPane1.setRightComponent(manageGoodsPanel);
        }
        }
    }//GEN-LAST:event_jTree1MouseClicked
    
    private void setEnvironment() {
        jSplitPane1.setDividerLocation(120);
        jSplitPane1.setRightComponent(new GeneralPanel());
        new NetUtil().start();
    }
    private AddPersonPanel addPersonPanel = new AddPersonPanel(this);
    private SearchPersonPanel searchPersonPanel = new SearchPersonPanel(this);
    private EditPersonPanel editPersonPanel = new EditPersonPanel(this);
    private DelPersonPanel delPersonPanel = new DelPersonPanel(this);
    
    private AddGoodsInfoPanel addGoodsInfoPanel = new AddGoodsInfoPanel(this);
    private DeleteGoodsInfoPanel delGoodsInfoPanel = new DeleteGoodsInfoPanel(this);
    private EditGoodsInfoPanel editGoodsInfoPanel = new EditGoodsInfoPanel(this);
    private SearchGoodsInfoPanel searchGoodsInfoPanel = new SearchGoodsInfoPanel(this);
    
    private Person person;
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSplitPane jSplitPane1;
    private javax.swing.JTree jTree1;
    private javax.swing.JPanel mainPanel;
    // End of variables declaration//GEN-END:variables

}
